﻿//-----------------------------------------------------------------------
// <copyright file="PivotTableCell.cs" company="Forebrain Technology, LLC">
//
// Copyright (c) Forebrain Technology, LLC. All rights reserved.
// 
// This source code is released under the Microsoft Public License (Ms-PL).
//
// </copyright>
//-----------------------------------------------------------------------
namespace PivotCollectionTools.Data
{
    using System;

    /// <summary>
    /// A cell in the a Pivot Table.
    /// </summary>
    [Serializable]
    public abstract class PivotTableCell
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PivotTableCell"/> class.
        /// </summary>
        /// <param name="column">The column the cell is associated with.</param>
        protected PivotTableCell(PivotTableColumn column)
        {
            this.Column = column;
        }

        /// <summary>
        /// Gets the column the cell is associated with.
        /// </summary>
        /// <value>The column of the pivot table cell.</value>
        public PivotTableColumn Column { get; private set; }

        /// <summary>
        /// Gets or sets the value of the cell.
        /// </summary>
        /// <value>The value of the pivot table cell.</value>
        public abstract string Value { get; set; }

        /// <summary>
        /// Gets the type of the data.
        /// </summary>
        /// <value>The type of the data.</value>
        public virtual PivotTableCellType DataType
        {
            get { return this.Column.Category.ValueType; }
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            if (this.Column == null)
            {
                return base.ToString();
            }

            return this.Column.Name;
        }
    }
}
